import requests
from requests.auth import HTTPDigestAuth

# Base URL for httpbin
BASE_URL = "https://httpbin.org"

# GET：/digest-auth/{qop}/{user}/{passwd}
# Prompts the user for authorization using Digest Auth.
# parameters: qop, user, passwd; string, (path)
def digest_auth():
    qop = "auth"
    user = "testuser"
    passwd = "testpass"
    url = f"{BASE_URL}/digest-auth/{qop}/{user}/{passwd}"
    response = requests.get(url, auth=HTTPDigestAuth(user, passwd))
    print(response.status_code)
    print(response.json())

# GET: /digest-auth/{qop}/{user}/{passwd}/{algorithm}
# Prompts the user for authorization using Digest Auth + Algorithm.
# parameters: qop, user, passwd, algorithm; string, (path)
def digest_auth_with_algorithm():
    qop = "auth"
    algorithm = "SHA-256"
    user = "testuser"
    passwd = "testpass"
    url = f"{BASE_URL}/digest-auth/{qop}/{user}/{passwd}/{algorithm}"
    response = requests.get(url, auth=HTTPDigestAuth(user, passwd))
    print(response.status_code)
    print(response.json())

# GET: /digest-auth/{qop}/{user}/{passwd}/{algorithm}/{stale_after}
# Prompts the user for authorization using Digest Auth + Algorithm.
# parameters: qop, user, passwd, algorithm, stale_after; string, (path)
# responses: 200(Successful authentication), 401(Unsuccessful authentication)
def digest_auth_with_algorithm_and_stale_after():
    qop = "auth"
    algorithm = "SHA-256"
    stale_after = "1"
    user = "testuser"
    passwd = "testpass"
    url = f"{BASE_URL}/digest-auth/{qop}/{user}/{passwd}/{algorithm}/{stale_after}"
    response = requests.get(url, auth=HTTPDigestAuth(user, passwd))
    print(response.status_code)
    print(response.json())

# Call the functions
digest_auth()
digest_auth_with_algorithm()
digest_auth_with_algorithm_and_stale_after()